from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from meiduo_admin.utils import MyNumbPage
from django.contrib.auth.models import Group, Permission
from .serializers import GroupSerializer, PremissionSerializer
from rest_framework.generics import ListAPIView
from rest_framework.decorators import action


class GroupViewSet(ModelViewSet):
    serializer_class = GroupSerializer
    queryset = Group.objects.all()
    pagination_class = MyNumbPage

    # permission/groups/simple
    @action(methods=['get'], detail=False)
    def simple(self, request):
        groups = self.get_queryset()
        serializer = self.get_serializer(instance=groups, many=True)

        return Response(serializer.data)


class SimpleView(ListAPIView):
    serializer_class = PremissionSerializer
    queryset = Permission.objects.all()
